﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once

#include "IError.h"
#include "Box3d.h"
#include "ElementId.h"
#include "GcmpDwgDxfInterface.h"


namespace gcmp
{
    class IModelView;

    class DwgErrorCode : public IErrorCode
    {
    public:
        enum DwgErrorType: int32_t
        {
            OK                  = 0,    ///< 成功
            UnknowError         = 1,    ///< 未知错误
            NotSupportUnit      = 2,    ///< 不支持的单位
            OpenDwgObjectError  = 3,    ///< 读取dwg数据失败
            CantExplodeEntity   = 4,    ///< 炸开entity失败
            NotSupportData      = 5,    ///< 不支持的数据，如圆弧、圆、椭圆形不在水平面内不导入
            NotSupportFunction  = 6,    ///< 不支持的功能
            InvalidEntity       = 7,    ///< 无效数据，比如直线特别短，圆的半径特别短，nurbs曲线没有点等
            CreateObjectError   = 8,    ///< 创建对象失败
            BoundingBoxTooLarge = 9,    ///< 包围盒太大，或者按原点导入时，导入对象距离原点距离太远
            NotFoundLayerStyle  = 10,   ///< 未查找到图层的样式
            ExportUnclassified  = 20,   ///< 导出时未分类错误
            ExportNullObjectId  = 21,   ///< 导出时得到空对象Id
            ExportUnknownError  = 22,   ///< 导出时未知错误

            HLRUnkownError      = 1001, ///< 消隐算法-未知错误
            HLRBodyDiscretized  = 1002, ///< 消隐算法-体离散错误 HLRErrorCode的Value返回离散失败的索引
            HLRTextDiscretized  = 1003, ///< 消隐算法-文本离散错误 HLRErrorCode的Value返回离散失败的索引
            HLRMoreTriangle     = 1004, ///< 消隐算法-离散的三角面太多，通过消隐算法的观察器得到

            HLRRSUnkownError    = 1100, ///< 消隐搜环算法-未知错误
            HLRRSMorePlace      = 1101, ///< 消隐搜环算法-曲线存在大量交点
            HLRRSEndlessLoop    = 1102, ///< 消隐搜环算法-死循环
            HLRRSOutOfMemory    = 1103, ///< 消隐搜环算法-内存溢出
        };

        struct DwgErrorInfo
        {
            ElementId modelViewId = ElementId::InvalidID;   ///< 视图Id，可能为空
            Box3d box;                                      ///< 可能发生错误的范围，可能为空
            std::vector<ElementId> ids;                     ///< 可能发生错误的构件，可能为空
        };

        DwgErrorCode() {}
        DwgErrorCode(DwgErrorType errorType) : m_errorType(errorType) {}
        DwgErrorCode(DwgErrorType errorType, const DwgErrorInfo& errorInfo) : m_errorType(errorType), m_errorInfo(errorInfo) {}
        DwgErrorCode(const DwgErrorCode& error) : m_errorType(error.m_errorType), m_errorInfo(error.m_errorInfo) {}

        virtual int GetCode() const override { return (int)m_errorType; }
        virtual std::wstring GetErrorCategory() const override { return L"DwgError"; }

        const DwgErrorInfo& GetErrorInfo() const { return m_errorInfo; }
        DwgErrorInfo& GetErrorInfo() { return m_errorInfo; }
    private:
        DwgErrorType m_errorType = OK;
        DwgErrorInfo m_errorInfo;
    };
}

